# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=regripper
pkgver=109.bdf7ac2
pkgrel=2
pkgdesc='Open source forensic software used as a Windows Registry data extraction command line or GUI tool.'
arch=('any')
groups=('blackarch' 'blackarch-forensic')
url='https://github.com/keydet89/RegRipper3.0'
depends=('perl' 'perl-parse-registry')
makedepends=('git')
license=('MIT')
options=('!emptydirs')
source=("$pkgname::git+https://github.com/keydet89/RegRipper3.0")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  ## Clean windows ^M new lines
  sed -i $'s/\r$//' *.pl
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin/"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md
  install -Dm 644 license.txt "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm -rf *.md

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname/
exec perl ./rip.pl "\${@}"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

